local hl__huairou = fk.CreateSkill {
  name = "hl__huairou",
}

Fk:loadTranslationTable{
  ["hl__huairou"] = "怀柔",
  [":hl__huairou"] = "每回合每种牌名限一次，出牌阶段，你可以重铸已废除装备栏对应的装备牌，然后从牌堆或弃牌堆中获得任意一张基本牌或普通锦囊牌。",

  ["#hl__huairou"] = "怀柔：你可以重铸装备牌并获得你指定牌名的非装备牌",
  ["hl__huairouFailed"] = "怀柔失败，牌堆与弃牌堆中没有该牌名的牌",

  ["$hl__huairou1"] = "为政若此，非国之务者也。",
  ["$hl__huairou2"] = "休兵止战，莫要再兴干戈。",
}

hl__huairou:addEffect("active", {
  anim_type = "drawcard",
  prompt = "#hl__huairou",
  card_num = 1,
  target_num = 0,
  interaction = function(self, player)
    local all_choices = Fk:getAllCardNames("bt")
    return UI.CardNameBox{
      choices = table.filter(all_choices, function(name)
        return not table.contains(player:getTableMark("hl__huairou_card_names-turn"), name)
      end),
      all_choices = all_choices,
    }
  end,
  can_use = function(self, player)
    return #player.sealedSlots ~= 0
  end,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeEquip and
    table.contains(player.sealedSlots, Util.convertSubtypeAndEquipSlot(Fk:getCardById(to_select).sub_type))
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local choice = self.interaction.data
    room:recastCard(effect.cards, effect.from, hl__huairou.name)
    room:addTableMark(player, "hl__huairou_card_names-turn", choice)
    local cards = {}
    local discard_pile = table.simpleClone(room.discard_pile)
    local draw_pile = table.simpleClone(room.draw_pile)
    local ids = table.filter(draw_pile, function (id)
      return Fk:getCardById(id).name == choice
    end)
    if #ids > 0 then
      local id = table.random(ids)
      table.insert(cards, id)
      table.removeOne(draw_pile, id)
    else
      ids = table.filter(discard_pile, function (id)
        return Fk:getCardById(id).name == choice
      end)
      if #ids > 0 then
        local id = table.random(ids)
        table.insert(cards, id)
        table.removeOne(discard_pile, id)
      end
    end
    if #cards > 0 then
      room:moveCards({
        ids = cards,
        to = player,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonJustMove,
        proposer = player,
        skillName = hl__huairou.name,
        moveVisible = false,
      })
    else
      room:doBroadcastNotify("ShowToast", Fk:translate("hl__huairouFailed"))
      return hl__huairou.name
    end
  end,
})

return hl__huairou
